package sz.szsmk.citizencard.mvp.presenter;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.model.network.GsdxNetApi;
import sz.szsmk.citizencard.model.network.bean.request.QuestionReq;
import sz.szsmk.citizencard.model.network.bean.response.QuestionRes;
import sz.szsmk.citizencard.mvp.contract.IQuestionContact;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.retrofitrxjava.NetworkDateSources;
import sz.szsmk.citizencard.retrofitrxjava.SubscribeResult;
import sz.szsmk.citizencard.util.AndroidUtils;

import javax.inject.Inject;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/7/25 21:42
 * description:
 */
public class QuestionPresenter extends IBasePresenter
        implements IQuestionContact.IQuestionPresenter<IQuestionContact.IQuestionView> {

    private NetworkDateSources mNetworkDateSource;
    GsdxNetApi gsdxNetApi;

    @Inject
    public QuestionPresenter(GsdxNetApi gsdxNetApi) {
        this.gsdxNetApi = gsdxNetApi;
        this.mNetworkDateSource = NetworkDateSources.getInstance();
    }

    @Override
    public void getQuestionInfo() {
        QuestionReq questionReq = new QuestionReq();
        questionReq.setAccess_token("sdfgsdf");
        questionReq.setDevice_id(AndroidUtils.getAndroidId(DaggerApplication.getIns()));
        questionReq.setSign("sfg");
        mNetworkDateSource.queryQA(questionReq, new SubscribeResult<QuestionRes>() {
            @Override
            protected void onOk(QuestionRes response) {
                ((IQuestionContact.IQuestionView) mView).getQuestionInfoSucc(response);
            }

            @Override
            protected void onFailure(QuestionRes response) {
                super.onFailure(response);
                ((IQuestionContact.IQuestionView) mView).getQuestionInfoFail(response);
            }

            @Override
            protected void onNext(QuestionRes response) {
                super.onNext(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }
}
